prefix          := @prefix@
abs_top_src_dir := @abs_top_srcdir@
XLEN            := @XLEN@
target_alias    := @target_alias@
ifeq ($(target_alias),)
RISCV_PREFIX_VAR :=
else
RISCV_PREFIX_VAR := RISCV_PREFIX=@target_alias@-
endif
instbasedir     := $(DESTDIR)$(prefix)
isa_src_dir     := $(abs_top_src_dir)/isa

all: isa

install: all
	install -d $(instbasedir)/share/riscv-tests/isa
	install -p -m 644 `find isa -maxdepth 1 -type f` $(instbasedir)/share/riscv-tests/isa

isa:
	mkdir -p isa
	$(MAKE) -C isa -f $(isa_src_dir)/Makefile src_dir=$(isa_src_dir) XLEN=$(XLEN) $(RISCV_PREFIX_VAR)

clean:
	[ ! -d isa ]        || $(MAKE) -C isa -f $(isa_src_dir)/Makefile src_dir=$(isa_src_dir) clean
	rm -rf target/
	rm -rf autom4te.cache/

.PHONY: isa clean

